package netbay;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

public class NetbayUtility {

	private static boolean isInit = false;

	public static void init(String configPath) {
		if (!isInit) {
			
			
			Properties prop = new Properties();
			FileInputStream fis = null;;
			Reader readIn = null;
			try {
				fis = new FileInputStream(configPath);
				readIn = new InputStreamReader(fis, "UTF-8");
			} catch (FileNotFoundException e2) {
				System.out.println("can't find the properties.xml");
				return;
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				prop.load(readIn);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			prop.list(System.out);
			
			WorkerManager.TCDRecvCmd = prop.getProperty("TCDRecvCmd");
			WorkerManager.JPMCRecvCmd = prop.getProperty("JPMCRecvCmd");
			WorkerManager.testCmd = prop.getProperty("testCmd");

			WorkerManager.TCDRecvDir = prop.getProperty("TCDRecvDir");
			WorkerManager.JPMCRecvDir = prop.getProperty("JPMCRecvDir");
			WorkerManager.JPMCDesDir = prop.getProperty("JPMCDesDir");
			
			SFTPManager.sftpRetryChance = Integer.parseInt(prop.getProperty("sftpRetryChance"));
			SFTPManager.sftpRetryDelay = Integer.parseInt(prop.getProperty("sftpRetryDelay"));
			
			SFTPManager.SFTPuser = prop.getProperty("SFTPuser");
			SFTPManager.SFTPhost = prop.getProperty("SFTPhost");
			SFTPManager.SFTPport = Integer.parseInt(prop.getProperty("SFTPPort"));
			SFTPManager.SFTPprivateKeyPath = prop.getProperty("SFTPprivateKeyPath");
			SFTPManager.SFTPpassPhrase = prop.getProperty("SFTPpassPhrase");
			SFTPManager.SFTPknowHostStrict = prop.getProperty("SFTPknowHostStrict").equalsIgnoreCase("true");
			
			SFTPManager.SFTPsendPath = prop.getProperty("SFTPsendPath");
			SFTPManager.SFTPrecvPath = prop.getProperty("SFTPrecvPath");
			
			TransactionManager.recvTcdStatus = prop.getProperty("recvTcdStatus");
			TransactionManager.beginSendJpmcStatus = prop.getProperty("beginSendJpmcStatus");
			TransactionManager.finSendJpmcStatus = prop.getProperty("finSendJpmcStatus");
			TransactionManager.recvJpmcStatus = prop.getProperty("recvJpmcStatus");
			TransactionManager.sendTcdStatus = prop.getProperty("sendTcdStatus");
			TransactionManager.resendSFTPStatus = prop.getProperty("resendSFTPStatus");
			TransactionManager.redownloadSFTPStatus = prop.getProperty("redownloadSFTPStatus");
			
			TransactionManager.dbUrl = prop.getProperty("dbUrl");
			TransactionManager.dbUser = prop.getProperty("dbUser");
			TransactionManager.dbPassword = prop.getProperty("dbPassword");
			TransactionManager.jdbcDriver = prop.getProperty("jdbcDriver");
			
			TransactionManager.JPMCcpaId = prop.getProperty("JPMCcpaId");
			TransactionManager.JPMCService = prop.getProperty("JPMCService");
			TransactionManager.JPMCAction = prop.getProperty("JPMCAction");
			TransactionManager.JPMCTransportProtocol = prop.getProperty("JPMCTransportProtocol");
			TransactionManager.JPMCTransportEndPoint = prop.getProperty("JPMCTransportEndPoint");
			TransactionManager.JPMCPayloadType = prop.getProperty("JPMCPayloadType");
			

			isInit = true;
		}
	}
}
